﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace MediaClient.Common
{
    public class AddWaterMarkHelper
    {
        private unsafe void* FlexApp = null;
        private static ConvertHelper flexEncoder = null;


        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern void* Convert_New();

        public unsafe AddWaterMarkHelper()
        {
            FlexApp = Convert_New();
        }

        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern int InitialFlex(string sourcefile,string targetfile);

        public unsafe int InitialFlexWaterMark(string filename, string targetfile)
        {
            InitialFlex(filename,targetfile);
            return 1;
        }

        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern int Convert_Start();

        public unsafe int StartFlexAddWaterMark()
        {
            Convert_Start();
            return 0;
        }


        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern byte* Convert_GetFBuffer();

        public unsafe byte* GetFirstFiledBuffer()
        {
            return Convert_GetFBuffer();
        }

        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern byte* Convert_GetSBuffer();

        public unsafe byte* GetSecondFiledBuffer()
        {
            return Convert_GetSBuffer();
        }

        //Convert_TotalFrame()
        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern int Convert_TotalFrame();

        public unsafe int GetTotalFrame()
        {
            return Convert_TotalFrame();
        }

        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern int Convert_CurrenFrametCount();

        public unsafe int GetCurrenFrametNum()
        {
            return Convert_CurrenFrametCount();
        }

        [DllImport("FlexAddWaterMark.dll")]
        private static unsafe extern void Convert_SetWaterMarkParam(int num,int count);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="num">水印间隔</param>
        /// <param name="count">水印强度</param>
        /// <returns></returns>
        public unsafe void SetWaterMarkParams(int num, int count)
        {
            Convert_SetWaterMarkParam(num, count);
        }


        public unsafe double GetProcess()
        {
            double process = 0.0;
            int total = GetTotalFrame();
            int current = GetCurrenFrametNum();
            process = (double)current / (double)total;
            return process;
        }

    }
}
